<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://eureka.yigolden.net/stringutils/sutaglib/1.0" prefix="su"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<title>添加预测信息</title>

  <!-- Bootstrap -->
    <link href="<%=request.getContextPath()%>/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/static/css/bootstrap-theme.min.css" rel="stylesheet">
    <link href="<%=request.getContextPath()%>/static/css/jumbotron.css" rel="stylesheet">
    
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="<%=request.getContextPath()%>/static/js/html5shiv.min.js"></script>
      <script src="<%=request.getContextPath()%>/static/js/respond.min.js"></script>
    <![endif]-->
    
    <script type="text/javascript">
    
    function submitForm(itemid){
    	
    	var domitorycount=document.getElementById("domitorycount");
    	var domitorynoisy=document.getElementById("domitorynoisy");
    	var domitorylayer=document.getElementById("domitorylayer");
    	var domitoryyear=document.getElementById("domitoryyear");
    	
    	if(domitorycount.value==0){
    		alert("请选择宿舍可住人数！");
    		domitorycount.focus();
			return false;
    	}
    	
    	if(domitorynoisy.value==2){
			alert("请选择宿舍噪音程度！");
			domitorynoisy.focus();
			return false;
		}
    	if(domitorylayer.value==0){
			alert("请选择宿舍层数！");
			domitorylayer.focus();
			return false;
		}
    	if(domitoryyear.value==0){
			alert("请选择宿舍年龄！");
			domitoryyear.focus();
			return false;
		}
    	return true;
    }
    
    </script>
     <script src="<%=request.getContextPath()%>/static/js/jquery.min.js"></script>
</head>
<body>
<jsp:include page="../Common/navHeader.jsp"></jsp:include>

<div class="container">

	 		<br> <br>
		<div class="row">
			<div class="col-lg-3 col-sm-2"></div>
			<!--左侧不用-->
			<div class="col-lg-6 col-sm-8 col-xs-12 text-center">
				<h3>宿舍自动预测</h3>
			</div>
			<!-- /.col-sm-4 -->
			<div class="col-lg-3 col-sm-2"></div>
			<!--右侧不用-->
		</div>

	  <br /> <br />
	  <div class="row">
		  <% request.setAttribute("tag", "backpropagationdeep"); %>
		  <jsp:include page="navLeftBarForGrouping.jsp"></jsp:include>

	      <div class="col-sm-9 col-xs-12">
		  
		  <div class="container">
			    <div class="row">

					<div class="col-sm-6">
					<form class="form-horizontal" method="post" onsubmit="return submitForm();">
			        <input type="hidden" name="action" value="predict" />     
			  		
				  		
			  		<div class="form-group">
			    		<label for="inputPassword3" class="col-sm-4 control-label">宿舍人数：</label>
			    		<div class="col-sm-8 dropdown">
			    		<select class="form-control" id="domitorycount" name="domitorycount">
			    			<option value="0">请填写宿舍人数：1-10</option>
			  				<option value="1">1</option>
			  				<option value="2">2</option>
			  				<option value="3">3</option>
			  				<option value="4">4</option>
			  				<option value="5">5</option>
			  				<option value="6">6</option>
			  				<option value="7">7</option>
			  				<option value="8">8</option>
			  				<option value="9">9</option>
			  				<option value="10">10</option>
						</select>
						</div>
			  		</div> 
			  		
			  		<div class="form-group">
			    		<label for="inputPassword3" class="col-sm-4 control-label">宿舍声音：</label>
			    		<div class="col-sm-8 dropdown">
			    		<select class="form-control" id="domitorynoisy" name="domitorynoisy">
			    			<option value="2">请填写宿舍噪音：0/1</option>
			  				<option value="0">0</option>
			  				<option value="1">1</option>
						</select>
						</div>
			  		</div> 
			  		
			  		<div class="form-group">
			    		<label for="inputPassword3" class="col-sm-4 control-label">宿舍楼层：</label>
			    		<div class="col-sm-8 dropdown">
			    		<select class="form-control" id="domitorylayer" name="domitorylayer">
			    			<option value="0">请填写宿舍楼层：1-10</option>
			  				<option value="1">1</option>
			  				<option value="2">2</option>
			  				<option value="3">3</option>
			  				<option value="4">4</option>
			  				<option value="5">5</option>
			  				<option value="6">6</option>
			  				<option value="7">7</option>
			  				<option value="8">8</option>
			  				<option value="9">9</option>
			  				<option value="10">10</option>
						</select>
						</div>
			  		</div> 
			  		
			  		<div class="form-group">
			    		<label for="inputPassword3" class="col-sm-4 control-label">宿舍年龄：</label>
			    		<div class="col-sm-8 dropdown">
			    		<select class="form-control" id="domitoryyear" name="domitoryyear">
			    			<option value="0">请填写宿舍年龄：1-10</option>
			  				<option value="1">1</option>
			  				<option value="2">2</option>
			  				<option value="3">3</option>
			  				<option value="4">4</option>
			  				<option value="5">5</option>
			  				<option value="6">6</option>
			  				<option value="7">7</option>
			  				<option value="8">8</option>
			  				<option value="9">9</option>
			  				<option value="10">10</option>
						</select>
						</div>
			  		</div>  		
			  		<div class="form-group">
			    		<div class="row text-right">
			      			<div class="col-xs-6 text-right">
			     				 <button type="submit" class="btn btn-success">提交预测</button>
			     		    </div>
			      			<div class="col-xs-6 text-left">
			      				<button type="reset" class="btn btn-warning">重新填写</button>
			      			</div>	
			    		</div>
			    		
			    		<div class="col-sm-offset-4 col-sm-8">
			    		<c:if test="${errorCode eq 1 }">
			          		<div class="alert alert-warning" role="alert" id="alert-warning">格式转换失败！</div>
			        	</c:if>
			        	<c:if test="${errorCode eq 2 }">
			          		<div class="alert alert-warning" role="alert" id="alert-warning">所有选项都不能为默认项！</div>
			        	</c:if>  
			        	</div>
			  		</div>
			        
			        
			        <input type="hidden" name="referrer" value="${fn:escapeXml(referer) }" />
			        
			      </form>
			      </div>
			      <div class="col-sm-6"></div>
			     </div>
			
			    </div> <!-- /container -->
	
	      </div>
      <div class="col-sm-1"></div><!--右侧不用-->
    </div>
 
    <jsp:include page="../Common/Footer.jsp"></jsp:include>

</div>

 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="<%=request.getContextPath()%>/static/js/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="<%=request.getContextPath()%>/static/js/bootstrap.min.js"></script>

	<script>
	window.getroommategroupBusy=false;
	window.isdisplay=false;
	$(document).ready(function() {
		
	    $("a.getroommategroup").click(function() {
	    	
	    	if(window.getroommategroupBusy)
	    		window.getroommategroupBusy=false;
	    	window.getroommategroupBusy=true;
    		
    		$("a.getroommategroup").addClass("disabled");
    		var universityid=$(this).data("university");
    		var domitoryid=$(this).data("domitory");
    		var postData={
    				universityid:universityid,
    				domitoryid:domitoryid
    		};
    		var id=$(this).data("id");
    		
    		$.ajax({
    			method:"POST",
    			url:"<%=request.getContextPath()%>/Roommate/SellRoommate",
    			contentType:"application/json",
    			data:JSON.stringify(postData),
    			dataType:"json",
    			success:function(data){
    				if(data.status==0){
    					if(window.isdisplay){
    						$("#"+id).closest("tr").hide();
    						window.isdisplay=false;
    					}
    					else{
		               		var $table = $("<table>")
		               		.addClass("table").addClass("table-hover").addClass("table-stripped")
		               		.append(
		               			$("<tr>")
		               			.css("background", "aliceblue")
		               			.append(
		               				$("<td>")
		               				.css("min-width", "60px")
		               				.text("机构名")
		               			)
		               			.append(
		               				$("<td>")
		               				.text("宿舍号")
		               			)
		               			.append(
		                			$("<td>")
		                			.text("用户名")
		                		)
		                		.append(
		                			$("<td>")
		                			.text("操作")
		                		)
		               		);
			                $.each(data.allocations, function() {
			                	$table
			                	.append(
			                		$("<tr>")
			                		.append($("<td>").text(this.universityname))
			                		.append($("<td>").text(this.domitoryid))
			                		.append(
			                			$("<td>")
			                			.append(
			                				$("<a>")
			                				.attr("href", "<%=request.getContextPath() %>/Account/ShowUserDetailInfo?userid=" + this.userid)
			                				.attr("target", "_blank")
			                				.text(this.username)
			                			)
			                		)
			                		.append(
			                			$("<td>")
			                			.append(
			                				$("<a>")
			                				.attr("href","#")
			                				.addClass("addMessageLink")
			                				.addClass("btn")
			                				.addClass("btn-link")
			                				.text("提出申请")
			                				.data("destination",this.userid)
			                				.click(test)
			                			)		
			                		)
			                	);
			                });
		               		
			                var $rootDiv = $("<div>")
			                	.addClass("table-responsive")
			                	.append($table);
		   					
			                $("#"+id).empty();
		   					$("#"+id).append($rootDiv);
		   					$("#"+id).closest("tr").show();
		   					window.isdisplay=true;
    					}
    				}else{
    					alert(data.message);
    				}
    			},
    			error:function(){
    				alert("服务器连接失败！");
    			},
    			complete:function(){
    				$("a.getroommategroup").removeClass("disabled");
    				window.getroommategroupBusy=false;
    			}
    		});
	    	return false;
	    });
	    
	    //$("a.addMessageLink").click(
	    //不明待解
    	function test() {
			if (window.addMessageBusy) return false;
			window.addMessageBusy = true;
			$("a.addMessageLink").addClass("disabled");
			
    		var destination = $(this).data("destination");
    		
    		var postData = {destination : destination};
    		$.ajax({
    			method: "POST",
    			url: "<%= request.getContextPath()%>/Message/AddMessage",
    			contentType : "application/json",
    			data: JSON.stringify(postData),
    			dataType : "json",
    			success: function(data) {
    				if (data.status == 0) {
    					alert("申请成功！");
    				} else {
    					alert(data.message);
    				}
    			},
    			error: function() {
    				alert("服务器连接失败！");
    			},
    			complete: function() {
    				$("a.addMessageLink").removeClass("disabled");
    				window.addMessageBusy = false;
    			}
    		});
    		return false;
    	};
	});

	</script>
</body>
</html>